import pandas as pd


def detect_outliers(df, column):
    Q1 = df[column].quantile(0.25)
    Q3 = df[column].quantile(0.75)
    IQR = Q3 - Q1
    lower_bound = Q1 - 1.5 * IQR
    upper_bound = Q3 + 1.5 * IQR
    outliers = df[(df[column] < lower_bound) | (df[column] > upper_bound)]
    return outliers

# 读取数据
task ='hezhou_min'
file_path = 'new_data_processed.xlsx'
df = pd.read_excel(file_path)

# 对GUILIN_TEMP列进行异常值检测
outliers = detect_outliers(df, task)

# 输出异常值及其对应的DATE
print("异常值及其对应的DATE:")
print(outliers[['record_date', task]])

# # 绘制训练集各特征的时序图
# plt.figure(figsize=(15, 7))
# plt.subplot(2, 2, 1)
# plt.plot(df_train['GUILIN_TEMP'], color='g', alpha=0.3)
# plt.title('GUILIN_TEMP时序图')
# plt.grid(True)

# plt.subplot(2, 2, 2)
# plt.plot(df_train['GUILIN_MAX'], color='g', alpha=0.3)
# plt.title('GUILIN_MAX时序图')
# plt.grid(True)

# plt.subplot(2, 2, 3)
# plt.plot(df_train['GUILIN_MIN'], color='g', alpha=0.3)
# plt.title('GUILIN_MIN时序图')
# plt.grid(True)

# plt.subplot(2, 2, 4)
# plt.plot(df_train['LIUZHOU_TEMP'], color='g', alpha=0.3)
# plt.title('LIUZHOU_TEMP时序图')
# plt.grid(True)
# plt.show()